{extend name="main" /}

{block name="body"}
{include file="breadcrumb" /}
<div class="layui-fluid">
    <div class="layui-card">
        <div class=" layui-card-header layuiadmin-card-header-auto">
            <form class="layui-form" method="get">
                <input type="hidden" name="bcid" value="{:input('bcid')}"><!--保留当前位置的bcid参数-->
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <a href="javascript:;" title="确认要删除吗？" class="layui-btn layui-btn-danger" id="deleteAll">
                            删除
                        </a>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px;">总计：{$count}</label>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline" style="width: 150px;">
                            <select name="parent_typeid" lay-filter="parent_typeid">
                                <option value="0">请选择</option>
                                {foreach name="parent_typelist" item="vo"}
                                <option value="{$vo.id}" {if $param.parent_typeid==$vo.id}selected{/if}>{$vo.title}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline" style="width: 150px;">
                            <select name="typeid" id="typeid">
                                <option value="0">请选择</option>
                                {foreach name="typelist" item="vo"}
                                <option value="{$vo.id}" {if $param.typeid==$vo.id}selected{/if}>{$vo.title}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="kw" class="layui-input" value="{$param.kw}">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-card-body">
            <table class="layui-table">
                <tr>
                    <th><b><input type="checkbox" id="selectAll"></b></th>
                    <th><b>ID</b></th>
                    <th><b>标题</b></th>
                    <th><b>大类</b></th>
                    <th><b>小类</b></th>
                    <th><b>项目</b></th>
                    <th><b>来源</b></th>
                    <th><b>方式</b></th>
                    <th><b>时间</b></th>
                    <th><b>操作</b></th>
                </tr>

                <tbody>
                {foreach name="list" item="vo"}
                <tr>
                    <td><input type="checkbox" name="ids[]" value="{$vo.id}" class="checkids"></td>
                    <td>{$vo.id}</td>
                    <td>{$vo.title}</td>
                    <td>{$vo.parent_typeid|get_typename}</td>
                    <td>{$vo.typeid|get_typename}</td>
                    <td>{$vo.project}</td>
                    <td>{$vo.source}</td>
                    <td>{if $vo.channel==1}脚本{elseif $vo.channel==2}后台添加{else}火车头{/if}</td>
                    <td>{$vo.create_time}</td>
                    <td>
                        <a href="{:url('edit',array('id'=>$vo['id']))}" data-width="800px" data-height="650px" title="编辑" class="layui-btn layui-btn-normal layui-btn-xs xn_open">
                            <i class="layui-icon layui-icon-edit"></i>编辑
                        </a>
                        <a href="{:Url('delete',array('id'=>$vo['id']))}" title="确认要删除吗？" class="layui-btn layui-btn-danger layui-btn-xs xn_delete">
                            <i class="layui-icon layui-icon-delete"></i>删除
                        </a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </div>
    </div>
    <div class="pages">
        {$list|raw}
    </div>
</div>
{/block}

{block name="js"}
<script>
    $(function() {
        var $selectAll = $("#selectAll");
        $selectAll.click(function() {
            if ($selectAll.prop("checked") == true) {
                $('.checkids').prop("checked", true);
            } else {
                $('.checkids').prop("checked", false);
            }
        });

        $("#deleteAll").click(function(){
            layer.confirm('确认删除选定内容吗?', {icon: 3, title:'操作提示'}, function(index){
                var ids = [];
                $('.checkids:checked').each(function(index,obj){
                    ids.push(obj.value);
                });
                $.get("{:Url('deleteAll')}?ids="+ids,function(data){
                    layer.msg(data.msg, {
                    time: 1000 
                    }, function(){
                    location.reload();
                    }); 
                });
            });
        });

        $("#clear").click(function(){
            $.get("{:Url('clear')}",function(data){
                layer.msg(data.msg, {
                time: 1000 
                }, function(){
                location.reload();
                }); 
            });
        });

    });

    function matching_run(matching=0,start=0,end=0){
        if(start==0){
            layer.msg('开始执行', {icon: 1,time: 0});
        }
        $.get("{:url('matching')}",{matching:matching,start:start,end:end},function(res){
            if(res.status){
                layer.msg(res.msg, {icon: 1,time: 0}); 
                matching_run(matching,res.data.start,res.data.end);
            }else{
                layer.msg(res.msg, {icon: 1,time: 2000},function(){
                    location.reload();
                });
            }
        });
    }

    var form = layui.form;
    form.on('select(parent_typeid)', function(res) { 
        $("#typeid").empty();
        if(res.value != 0){
            $.get("{:url('admin/DataType/getSonType')}?pid="+res.value,function(result){
                if(result.status){
                    $("#typeid").append(new Option('请选择',0));
                    $.each(result.data,function(index,item){
                        $("#typeid").append(new Option(item.title,item.id));
                    });
                    form.render("select");
                }
            });
        }else{
            $("#typeid").append(new Option('请选择',0));
            form.render("select");
        }
    })

</script>
{/block}